﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.ServiceModel.Syndication;
using ServiceModel.Syndication.LEAP2A;

namespace LeapExamples {
    public partial class Export : Form {
        public Export() {
            InitializeComponent();
        }

        public static void ExportExample() {
            LeapFeed feed = new LeapFeed();
            List<SyndicationItem> items = new List<SyndicationItem>();

            feed.Items = items;
            feed.LocalNamespace = "http://yoururl.com/";
            feed.LocalSchemeNamespace = "http://www.pebblepad.co.uk/leap2a/schemes#";

            feed.Id = "http://yoururl.com/uniqueid";
            feed.LastUpdatedTime = DateTime.Now;
            feed.Authors.Add(new SyndicationPerson("someone@somewhere.com", "John Smith", null));

            feed.Title = new TextSyndicationContent("Portfolio Items");

            LeapItem entry = new LeapItem(feed);
            entry.Id = "http://yoururl.com/uniqueid/1";
            entry.Title = new TextSyndicationContent("Title");
            entry.PublishDate = DateTime.Now;
            entry.LastUpdatedTime = DateTime.Now;
            entry.Content = new TextSyndicationContent("Some content");

            entry.LeapActiveTime = new LeapTimeSpan(120);
            entry.LeapType = LeapTypes.Activity;

            items.Add(entry);

            LeapItem subentry = new LeapItem(feed);
            subentry.Id = "http://yoururl.com/uniqueid/2";
            subentry.Title = new TextSyndicationContent("Sub-Title");
            subentry.PublishDate = DateTime.Now;
            subentry.LastUpdatedTime = DateTime.Now;
            subentry.Content = new TextSyndicationContent("Some more content");

            subentry.LeapType = LeapTypes.Plan;

            items.Add(subentry);

            entry.Has(LeapLinkPair.Related, subentry);

            if (File.Exists("leap2a.xml")) {
                File.Delete("leap2a.xml");
            }

            XmlTextWriter xtw = new XmlTextWriter("leap2a.xml", System.Text.Encoding.UTF8);
            feed.SaveAsAtom10(xtw);
            xtw.Close();
        }
    }
}
